#!/usr/bin/env php
<?php
/**
 * Created by b17
 * 2/15/12 9:19 PM
 */

require_once "cron.php";
$pidFile = "delivery.pid";
$module = "delivery";
if (file_exists($pidFile)) {
    w("Delivery task in already running.", $module);
} else {
    $fp = fopen($pidFile, 'w');
    w("Sending messages...", $module);
    $start = microtime(true);
    $deliveryMailer = new \Managers\DeliveryMailer();
    try {
        $deliveryMailer->send();
    } catch (Exception $e) {
        w($e->getMessage() . PHP_EOL . $e->getTraceAsString(), $module);
    }
    $time = microtime(true) - $start;
    w("Total time: " . number_format($time, 3), $module);
    fclose($fp);
    unlink($pidFile);
}
 